'use strict';
import Base from './base.js';
// 美易通订单类控制器请求方法
module.exports = class extends Base {
// 获取列表通用的接口
  async getorderlistallAction() {
    const orcode = this.post('orcode');
    const jsonshop = this.post('jsonshop');
    const floor = this.post('floor');
    const ismanage = this.post('ismanage');
    const user_id = this.post('user_id');
    const select_info = this.post('select_info');
    const page = this.post('page');
    const size = this.post('size');
    const nowpage = page * size;
    switch (floor) {
      case 0:
      case 1:
        var info = await this.model().query(' SELECT og.name as username,od.name as shopname,og.sex,oso.addtime,og.headurl,oso.status,oso.fenpei,oso.recemoney,oso.cardreduce,oso.usebalance,usegiftbalance,og.id as guestid,oso.id as orderid FROM `think_or_shop_order` oso LEFT JOIN `think_or_guest` og ON oso.guestid = og.id LEFT JOIN `think_or_department` od ON od.id = oso.departmentid WHERE od.id IN (' + jsonshop + ') ' + select_info + ' ORDER BY oso.addtime DESC LIMIT ' + nowpage + ',' + size + ' ');
        break;
      case 2:
        var info = await this.model().query(' SELECT og.name as username,od.name as shopname,og.sex,oso.addtime,og.headurl,oso.status,oso.fenpei,oso.recemoney,oso.cardreduce,oso.usebalance,usegiftbalance,og.id as guestid,oso.id as orderid FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_shop_order` oso ON osy.orderid = oso.id LEFT JOIN `think_or_department` od ON oso.departmentid = od.id  WHERE au.bumenid = ' + jsonshop + ' ' + select_info + ' GROUP BY osy.orderid ORDER BY oso.addtime DESC LIMIT ' + nowpage + ',' + size + ' ');
        break;
      case 3:
        if (ismanage == 1) {
          info = await this.model().query(' SELECT og.name as username,od.name as shopname,og.sex,oso.addtime,og.headurl,oso.status,oso.fenpei,oso.recemoney,oso.cardreduce,oso.usebalance,usegiftbalance,og.id as guestid,oso.id as orderid FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_shop_order` oso ON osy.orderid = oso.id LEFT JOIN `think_or_department` od ON oso.departmentid = od.id  WHERE au.xiaozuid  = ' + jsonshop + ' ' + select_info + ' GROUP BY osy.orderid ORDER BY oso.addtime DESC LIMIT ' + nowpage + ',' + size + ' ');
        } else {
          info = await this.model().query(' SELECT og.name as username,od.name as shopname,og.sex,oso.addtime,og.headurl,oso.status,oso.fenpei,oso.recemoney,oso.cardreduce,oso.usebalance,usegiftbalance,og.id as guestid,oso.id as orderid FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_shop_order` oso ON osy.orderid = oso.id LEFT JOIN `think_or_department` od ON oso.departmentid = od.id  WHERE osy.userid  = ' + user_id + ' ' + select_info + ' GROUP BY osy.orderid ORDER BY oso.addtime DESC LIMIT ' + nowpage + ',' + size + ' ');
        }
        break;
    }
    return think.isEmpty(info) ? this.json({'code': '200', 'msg': '没有数据...', 'data': ''}) : this.json({'code': '100', 'msg': '查询成功...', 'data': info});
  }
  // 根据orderid 查询order的详细信息
  async getorderinfoAction() {
    const orderid = this.post('orderid');
    const order = await this.model().query(' SELECT og.name,oso.order_sn,oso.addtime,oso.recemoney,oso.cardreduce,oso.usebalance,oso.usegiftbalance,od.name as shopname,au.name as gendanname,op.name as jobname FROM `think_or_shop_order` oso LEFT JOIN `think_or_guest` og ON oso.guestid = og.id LEFT JOIN `think_or_department` od ON oso.departmentid = od.id LEFT JOIN `think_or_app_user` au ON oso.gendanid = au.id LEFT JOIN `think_or_position` op ON au.positionid = op.id WHERE oso.id = ' + orderid + ' ');
    const order_goods = await this.model().query(' SELECT type,typename,num,price,amount,consumetype FROM `think_or_shop_orderinfo` WHERE orderid = ' + orderid + ' ');
    const fuwu = await this.model().query('SELECT  osy.id,au.name,op.name as jobname FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_position` op ON au.positionid = op.id WHERE osy.orderid = ' + orderid + ' ');

    return think.isEmpty(order) ? this.json({'code': '200', 'msg': '没有数据...', 'data': ''}) : this.json({'code': '100', 'msg': '查询成功...', 'order': order, 'order_goods': order_goods, 'fuwu': fuwu});
  }
  // 获取客户订单列表
  async getorderguestlistAction() {
    const guest_id = this.get('guest_id');
    const page = this.get('page');
    const size = this.get('size');
    const nowpage = page * size;
    const info = await this.model().query(' SELECT  og.name as username,od.name as shopname,og.sex,oso.addtime,og.headurl,oso.status,oso.fenpei,oso.recemoney,oso.cardreduce,oso.usebalance,usegiftbalance,og.id as guestid,oso.id as orderid FROM `think_or_shop_order` oso LEFT JOIN `think_or_guest` og ON oso.guestid = og.id LEFT JOIN `think_or_department` od ON oso.departmentid = od.id WHERE oso.guestid = ' + guest_id + ' ORDER BY oso.addtime DESC LIMIT ' + nowpage + ',' + size + '  ');
    return think.isEmpty(info) ? this.json({ 'code': '200', 'msg': '没有数据...', 'data': '' }) : this.json({ 'code': '100', 'msg': '查找成功...', 'data': info });
  }

// bottom
};
